package cn.sdut.training.web.action;

import java.util.List;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;

import cn.sdut.training.domain.Academy;
import cn.sdut.training.service.TrainingService;

public class AcademyAction extends ActionSupport{

	private static final long serialVersionUID = 3691251281212576499L;
	private Academy academy;
	
	private Long id;
	private List<Academy> academyList;
	private Long[] idList;
	
	@Resource
	private TrainingService trainingService;
	
	/**
	 * 转到保存页面
	 * @return
	 */
	public String toSavePage(){
		return "toSavePage";
	}
	
	/***
	 * 执行保存方法
	 * @return
	 */
	public String save(){
		trainingService.saveAcademy(academy);
		return "toList";
	}
	
	/**
	 * 转到列表页面
	 * @return
	 */
	public String toListPage(){
		academyList = trainingService.findAllAcademy();
		return "toListPage";
	}
	
	/**
	 * 执行删除操作
	 * @return
	 */
	public String delete(){
		for(Long id:idList){
			trainingService.deleteAcademy(id);
		}
		return "toList";
	}
	
	/**
	 * 转到编辑页面
	 * @return
	 */
	public String toEditPage(){
		academy = trainingService.getAcademyById(id);
		return "toEditPage";
	}
	
	/**
	 * 执行更新操作
	 * @return
	 */
	public String update(){
		academy.setId(id);
		trainingService.updateAcademy(academy);
		return "toList";
	}

	
	//-------------------------------------------------
	public Academy getAcademy() {
		return academy;
	}

	public void setAcademy(Academy academy) {
		this.academy = academy;
	}

	public List<Academy> getAcademyList() {
		return academyList;
	}

	public void setAcademyList(List<Academy> academyList) {
		this.academyList = academyList;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getIdList() {
		return idList;
	}

	public void setIdList(Long[] idList) {
		this.idList = idList;
	}

	
}
